/**
 * Class: AbstractPoint
 * Base for LonLat and XY, etc
 */
var AbstractPoint = SMap.Class({
	init: function(left, top) {
		var left = (left == null) ? 0 : parseFloat(left);
		var top = (top == null) ? 0 : parseFloat(top);
		this.fromArray([left, top]);
	},
	/**
	* Function: ensureWithin
	* if bounds does no contain point, then set this to closest point within bounds
	*
	* Parameters:
	* bounds - <Bounds>
	*  
	* Returns:
	* Boolean - if point was within return true
	*/
	ensureWithin: function(bounds) {
		var c =	this.toArray();
		var x, y, l, r, t, b;
		
		x = c[0];
		y = c[1];
		
		// make sure right > left & bottom < top
		with(bounds) {
			l = Math.min(left, right);
			r = Math.max(left, right);
			b = Math.min(bottom, top);
			t = Math.max(bottom, top);
		}
		
		if (x > r) x = r;
		if (x < l) x = l;
		if (y > t) y = t;
		if (y < b) y = b;
		
		if ((x != c[0]) || (y != c[1])) {
			this.fromArray([x, y]);
			return false;
		}
		return true;
	},
	/**
	* Function: equal
	* 
	* Parameters:
	* abstractpoint - <AbstractPoint>
	* precision - maximum aproved difference between every number (x,y). default = 0
	* 
	* Returns:
	* Boolean - if two points are equal
	*/
	equal: function(abstractpoint, precision) {
		if (precision == null) precision = 0;
 		var a = this.toArray();
 		var b = abstractpoint.toArray();
 		return (Math.abs(a[0]-b[0]) <= precision) && (Math.abs(a[1]-b[1]) <= precision);
    }
});
